package io.adrainty.bolee.insurance.web;

import io.adrainty.bolee.framework.commons.basic.EnableEnum;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.user.SubjectContentUtil;
import io.adrainty.bolee.framework.commons.user.UserEntity;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.insurance.models.entity.CustomerRelationEntity;
import io.adrainty.bolee.insurance.service.ICustomerRelationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>MineController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description 我的tab页
 * @since 2025/8/25 10:33:34
 */

@Tag(name = "我的tab页")
@RestController
@RequestMapping("/mined")
public class MineController {

    @Resource
    private ICustomerRelationService customerRelationService;

    @PostMapping("my-relation")
    @Operation(summary = "根据当前登录人信息获取关系网")
    public ResultDTO<List<CustomerRelationEntity>> myRelation() {
        UserEntity userEntity = SubjectContentUtil.getUserVO();
        CustomerRelationEntity relationEntity = CustomerRelationEntity.builder()
                .customerId(userEntity.getId())
                .dataState(EnableEnum.ENABLE)
                .build();
        List<CustomerRelationEntity> result = customerRelationService.findRelationList(relationEntity);
        result.forEach(CustomerRelationEntity::desensitize);
        return ResultDTOUtil.success(result);
    }

}
